package com.boylegu.springboot_vue.service.impl;

import com.boylegu.springboot_vue.dao.TeachersRepository;
import com.boylegu.springboot_vue.entities.Teachers;
import com.boylegu.springboot_vue.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeachersRepository teachersRepository;

    @Override
    public void deleteById(String id) {
        teachersRepository.delete(id);
    }

    public Teachers save(Teachers teacher) {
        return teachersRepository.save(teacher);
    }

    @Override
    public Page<Teachers> findAll(Pageable page) {
        Page<Teachers> results = this.teachersRepository.findAll(page);
        return results;
    }

    @Override
    public List<Teachers> findAll() {
        return teachersRepository.findAll();
    }

    @Override
    public Teachers findById(String id) {
        return teachersRepository.findById(id);
    }

    public int count() throws Exception {
        long size = teachersRepository.count();
        int count = Integer.valueOf(String.valueOf(size));
        return count;
    }

}
